< previous page page_236 next page >

Page 236
Solution 25
Universal Identifiers, Part 1
There are really only two approaches to dealing with 128-bit variables in Visual Basic: You need to create either an array or a user-defined type (structure). The Windows solution is to use a structure. A large part of the trick to translating a C header file to Visual Basic is to figure out which statements are actually relevant to the task. Take another look at the listing, but this time with comments added:
#ifndef GUID_DEFINED         // Skip the following if the _
                             // GUID_DEFINED is already defined.
#define GUID_DEFINED         // Define the GUID_DEFINED constant - no value.
typedef struct  _GUID        // Define a structure (user-defined type)
    {
    DWORD Data1;             // 32 bit value
    WORD Data2;              // 16 bit value
    WORD Data3;              // 16 bit value
    BYTE Data4[ 8 ];         // 8 x 8 bits = 64 bits
    }  GUID;   // The GUID structure is 32+16+16+64 = 128 bits

#endif                       // !GUID DEFINED
                             // End of the part to skip if GUID_DEFINED is
                             // already defined
The use of conditional compilation constants, such as the GUID_DEFINED constant above, is very common in Windows header files. The first time a program includes this header file, GUID_DEFINED will not be defined. That means that the lines up to the #endif statement will be processed by the compiler, including a line that defines the GUID_DEFINED constant. The next time the header file is included by a program, the compiler will see that the GUID_DEFINED constant is already defined and skip over the code up to the #endif statement. This will prevent the GUID structure from being defined a second timean error in C++.
This differs from the system in Visual Basic, where you simply add modules to a project. In C++, it is possible for files to include header files. These files are treated as if they are part of the main program file. But a header file can also include additional header files. If multiple files include the same header file (as

 
< previous page page_236 next page >